/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package VideoStreaming;

/**
 *
 * @author naveen
 */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import java.util.Hashtable;
import net.jxta.j2me.PeerNetwork;
import net.jxta.j2me.Message;
import net.jxta.j2me.Element;
public class Connection {

  
    Configuration config;
    VideoStreaming vstrm;

    
   
  /*  private boolean poll() {
        if (peer == null || !connected) {
            // not yet connected
            return false;
        }
         Message msg = null;
        try {
            long startTime, endTime;
            if (QUANTIFY) {
                startTime = System.currentTimeMillis();
            }
            // timeout must not be zero: zero means block forever
            if (peer != null) {
                msg = peer.poll(config.getPollInterval()*1000);
            }
            if (QUANTIFY) {
                endTime = System.currentTimeMillis();
                System.out.println("poll took " +
                                   Long.toString(endTime-startTime));
            }
        } catch (IOException ex) {
          /*  //ex.printStackTrace();
            showAlert("Poll",
                      "Error polling relay: " + ex.getMessage(),
                      AlertType.ERROR,
                      DEFAULT_ALERT_TIMEOUT,
                      initForm);*/
/*            return false;
        }

        if (msg == null) {
            return false;
        }

        Element el = null;
        String name = null;
        String id = null;
        for (int i=0; i < msg.getElementCount(); i++) {
            el = msg.getElement(i);
            if (Message.PROXY_NAME_SPACE.equals(el.getNameSpace())) {
		String elementName = el.getName();
                if (Message.NAME_TAG.equals(elementName)) {
                    name = new String(el.getData());
		} else if (Message.ID_TAG.equals(elementName)) {
                    id = new String(el.getData());
		}
	    }
	}

        if (name != null) {
            if (name.indexOf(config.TALKNAME_PREFIX) >= 0) {
                name = name.substring(config.TALKNAME_PREFIX.length());
            }
        if(id != null && !"".equals(id))
       {
                   mateIDS.put(name, id);

                }
            }


        String sender = null;
        String message = null;

        String imageCaption = null;
        String imageFileName = null;
        byte[] imageData = null;

        boolean isDisplayable = true;

         for(int i=0;i<msg.getSize();i++)
        {
            el = msg.getElement(i);
            if ("requestId".equals(el.getName())) {
                responseId = Integer.parseInt(new String(el.getData()));
                System.out.println ("ResponseId: " + responseId);
            }else if ("JxtaTalkSenderName".equals(el.getName())) {
                sender = new String(el.getData());
            } else if ("JxtaTalkSenderMessage".equals(el.getName())) {
                message = new String(el.getData());
            } else if ("Caption".equals(el.getName())) {
                imageCaption = new String(el.getData());
            } else if ("FileName".equals(el.getName())) {
                imageFileName = new String(el.getData());
            } else if ("DataBlock".equals(el.getName())) {
                imageData = el.getData();
                isDisplayable = false;
            }

            if (DEBUG) {
                System.out.print(i + " " + el.getName());
                if (isDisplayable) {
                    System.out.print(" " + new String(el.getData()));
                }
                System.out.println();
            }
            isDisplayable = true;
        }

        /*if (imageData != null) {
            String caption =
                imageCaption == null ? imageFileName : imageCaption;
          //  imageCanvas.createImage(imageData, caption, sender);
	    display.setCurrent(imageCanvas);
        }*/

  /*      if (sender != null && message != null) {
            if (sender.indexOf(config.TALKNAME_PREFIX) >= 0) {
                sender = sender.substring(config.TALKNAME_PREFIX.length());
            }
            replyBuddy = sender;
            String displayedMsg = sender + "> " + message + "\n";

            // keep the last DEFAULT_SCROLL messages, the rest scroll off


            // pop an alert for a millisecond to get a notification beep
          /*  showAlert("", "", AlertType.INFO, 1, initForm);*/
        }

	//return true;
   // }

    //}


